package cn.ad.service;

import cn.ad.entity.BaseReportValue;
import cn.ad.handler.SqlSessionHandler;
import cn.ad.model.IBaseRptModel;
import cn.ad.model.Search;
import cn.ad.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
public class GeoRptSerivce {

	@Autowired
	private SqlSessionHandler sqlSessionHandler;

	public BaseReportValue getCitysSumReport(int cid, List<Integer> citys, Date startTime, Date endTime) {
		Date currentDateStartTime = Utils.getStartTime(Calendar.getInstance().getTime());
		if(currentDateStartTime.getTime()<startTime.getTime()){
			return new BaseReportValue();
		}
		Search search = new Search(cid,startTime,endTime);
		Utils.resizeSearch(search, startTime, endTime);
		search.setIds(citys);
		return sqlSessionHandler.selectOne("rptGeoMapper.report:geo:sum", search);
	}

	public List<IBaseRptModel> getCityReportList(int cid, Date startTime, Date endTime) {
		Date currentDateStartTime = Utils.getStartTime(Calendar.getInstance().getTime());
		if(currentDateStartTime.getTime()<startTime.getTime()){
			return new ArrayList<>();
		}
		Search search = new Search(cid,startTime,endTime);
		Utils.resizeSearch(search, startTime, endTime);
		return sqlSessionHandler.selectList("rptGeoMapper.report:geo:sum:list", search);
	}
	
}
